package com.atguigu.day07.HomeWork;

import java.util.Scanner;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/6 19:00
 * @注释 输入三条边，判断是什么三角形
 */
public class HomeWork1{
    //判断是否是一个三角形
    public boolean isTriangle(double a, double b, double c){
        boolean flag = false;
        if(a > 0 && b > 0 && c > 0 && a + b > c && a + c > b && b + c > a){
            flag = true;
        }else{
            System.out.println("这不是一个三角形");
        }
        return flag;
    }
    //判断是否是一个直角三角形
    public boolean isRightTriangle(double a, double b, double c){

        boolean flag = false;
        if(a > 0 && b > 0 && c > 0 && a + b > c && a + c > b && b + c > a){
            if(a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a){
                flag = true;
            }
        }

        return flag;
    }
    //判断是否是一个等腰三角形
    public boolean isIsosocelesTriangle(double a, double b, double c){
        boolean flag = false;
        if(a > 0 && b > 0 && c > 0 && a + b > c && a + c > b && b + c > a){
            if(a == b || b == c || c == a){
                flag = true;
            }
        }

        return flag;
    }
    //判断是否是一个等边三角形
    public boolean isEquilateralTriangle(double a, double b, double c){
        boolean flag = false;
        if(a > 0 && b > 0 && c > 0){
            if(a == b && b == c){
                flag = true;
            }
        }
        return flag;
    }
    //根据三条边，用海伦公式求面积
    public double area(double a, double b, double c){
        double p = (a + b + c) / 2;
        return Math.sqrt(p * (p - a) * (p - b) * (p - c));
    }
    //求周长
    public double perimeter(double a, double b, double c){
        return (a + b + c);
    }
}

class HomeWork1Test{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入三角形的三条边：");
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = sc.nextDouble();
        HomeWork1 h = new HomeWork1();
        if(h.isTriangle(a, b, c)){
            System.out.println("这是一个三角形");
            System.out.println("三角形的面积是：" + h.area(a, b, c));
            System.out.println("三角形的周长是：" + h.perimeter(a, b, c));
        }
        if(h.isRightTriangle(a, b, c)){
            System.out.println("这是一个直角三角形");
        }
        if(h.isIsosocelesTriangle(a, b, c)){
            System.out.println("这是一个等腰三角形");
        }
        if(h.isEquilateralTriangle(a, b, c)){
            System.out.println("这是一个等边三角形");
        }

    }
}